Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
5 | Cart: new function () { |
||
6 | this.addItem = function (itemOfferPriceId, count, btn, callback) { |
||
7 | inji.Server.request({ |
||
8 | url: 'ecommerce/cart/add', |
||
9 | data: { |
||
10 | itemOfferPriceId: itemOfferPriceId, |
||
11 | count: count |
||
12 | }, |
||
13 | success: function (data) { |
||
14 | if (callback) { |
||
15 | callback(data, btn); |
||
16 | } |
||
17 | inji.Server.request({ |
||
18 | url: 'ecommerce/cart/getCart', |
||
19 | success: function (data) { |
||
20 | $("#cart,.cartplace").html(data); |
||
21 | } |
||
22 | }); |
||
23 | } |
||
24 | }, btn); |
||
25 | }; |
||
26 | this.calcSum = function (form) { |
||
27 | if (form === undefined) { |
||
28 | form = $('.ecommerce .cart-order_page form'); |
||
29 | } |
||
30 | else { |
||
31 | form = $(form) |
||
32 | } |
||
33 | var formData = new FormData(form[0]); |
||
34 | $('.ecommerce .cart-order_page').prepend($('<div style = "position:absolute;width:' + $('.ecommerce .cart-order_page').width() + 'px;height:' + $('.ecommerce .cart-order_page').height() + 'px;background-color: rgba(255, 255, 255, 0.4);z-index:1000000"></div>')); |
||
35 | inji.Server.request({ |
||
36 | url: form.attr('action'), |
||
37 | type: 'POST', |
||
38 | data: formData, |
||
39 | dataType: 'html', |
||
40 | processData: false, |
||
41 | success: function (data) { |
||
42 | $('.ecommerce .cart-order_page').html($(data).find('.ecommerce .cart-order_page').html()); |
||
43 | if ($(data).find('.alert').length > 0) { |
||
44 | $.each($(data).find('.alert'), function () { |
||
45 | //$('.ecommerce .cart-order_page').prepend(this.outerHTML) |
||
46 | }) |
||
47 | } |
||
48 | } |
||
49 | }); |
||
50 | }; |
||
51 | this.delItem = function (cart_item_id, form) { |
||
52 | $('.cart_item_id' + cart_item_id).remove(); |
||
53 | this.calcSum(form); |
||
54 | }; |
||
55 | this.delItemWidget = function (cart_item_id, callback) { |
||
56 | inji.Server.request({ |
||
57 | url: '/ecommerce/cart/deleteItem?cartItemId=' + cart_item_id, |
||
58 | success: function (data) { |
||
59 | $("#cart,.cartplace").html(data); |
||
60 | if (callback !== undefined) { |
||
61 | callback(); |
||
62 | } |
||
63 | } |
||
64 | }); |
||
65 | } |
||
66 | }, |
||
67 | toggleFav: function (itemId, btn, noChangeText) { |
||
159 |